package com.dhy.msg;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

//用来封装消息的工具类
public class MessageUtils
{
    public static  String getMessage(boolean isSystemMessgae,String fromName,Object message)
    {
        try {
            //服务端发送给浏览器的消息格式
            ResultMessage result=new ResultMessage();
            result.setSystem(isSystemMessgae);
            result.setMessage(message);
            //不是系统消息
            if(fromName!=null)
            {
                result.setFromName(fromName);
            }
            //Jackson的主要类
            ObjectMapper mapper=new ObjectMapper();
            return mapper.writeValueAsString(result);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }
}
